<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
	<script src="../node_modules/axios/dist/axios.min.js"></script>
</head>
<body>
<button>发送请求</button>
<button>取消请求</button>
</body>
<script type="module">
	import axios from "./myAxios.js";
	axios.defaults.baseURL = "http://zhangpeiyue.com";
	axios.defaults.method = "get";
	// axios.defaults.timeout = 1000;
	const btns = document.querySelectorAll("button");
	let cancelFn;
	btns[0].onclick = function () {
		if (cancelFn instanceof Function) cancelFn();
		axios("/scoreList", {
			cancelToken: new axios.CancelToken(function (fn) {
				cancelFn = fn;
			})
		}).then(value => {
			cancelFn = null;
			console.log(value);
		}).catch(err => {
			console.log(1111, axios.isCancel(err), err);
		});
	}
	btns[1].onclick = function () {
		if (cancelFn instanceof Function)
			cancelFn();
	}
	
	// console.log(result);
</script>
</html>